package poo.esempi;

import java.util.Scanner;

import poo.util.Stack;
import poo.util.StackConcatenato;

public class PalindromaStack {

	public static void main(String[] args) {
		String schema = ".*\\$.*";
		Scanner sc = new Scanner(System.in);
		System.out.println("Fornisci una frase.");
		String linea = sc.nextLine();
		if (!linea.matches(schema)) {
			System.out.println("GAYYYYYY");
			System.exit(-1);
		}
		Stack<Character> pila = new StackConcatenato<Character>();
		int i = 0;
		while (linea.charAt(i) != '$') {
			pila.push(linea.charAt(i));
			i++;
		}
		while (i < linea.length() && !pila.isEmpty()) {
			char x = pila.pop();
			if (x != linea.charAt(i))
				break;
			i++;
		}
		if (i == linea.length() && pila.isEmpty())
			System.out.println("Palindroma OK");
		else {
			System.out.println("No palindroma");
			System.exit(-1);
		}

	}
}
